home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / helper / source / helper.c < prev    next >
Text File  |  1991-10-18  |  9KB  |  440 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <string.h>
  4. #include    <ctype.h>
  5. #include    <mos.h>
  6. #include    "scrn.h"
  7. #include    "keyword.h"
  8. #include    "graphic.h"
  9. #include    "dir.h"
  10. #include    "file.h"
  11. #include    "oaklib.h"
  12. #include    "coldef.h"
  13.  
  14. #define    DEBUG
  15.  
  16. /*******
  17. char    *strdup(char *str);
  18. ********/
  19.  
  20. extern char    *crent_drive;
  21.  
  22.        char    index_file[128];
  23.        int    cur_x=0;
  24.        int    cur_y=0;
  25. static int    kb_act=0;
  26. static int     kb_flg=0;
  27. static int     ch_bak=0;
  28. static unsigned ec_bak=0;
  29.  
  30. void    put_put(int x,int y,int len,int pos,char *str,char *att)
  31. {
  32.     int     i,col;
  33.     char    tmp[4];
  34.     static int kan_col[]={ 15,1,2,3,4,5,6,7,0,9,10,11,12,13,14,8 };
  35.  
  36.     for ( i = 0 ; i < len ; ) {
  37.     col = kan_col[*att];
  38.     if ( i == pos )
  39.         col |= 8;
  40.  
  41.     if ( iskanji(*str) && iskanji2(*str+1) ) {
  42.         tmp[0] = *(str++);
  43.         tmp[1] = *(str++);
  44.         tmp[2] = '\0';
  45.         if ( (x + 16) > 640 ) {
  46.         x = 0;
  47.         y += 16;
  48.         }
  49.         gputs(x,y,15,col,tmp);
  50.         x += 16;
  51.         att += 2;
  52.         i += 2;
  53.     } else {
  54.         tmp[0] = *(str++);
  55.         tmp[1] = '\0';
  56.         if ( (x + 8) > 640 ) {
  57.         x = 0;
  58.         y += 16;
  59.         }
  60.         gputs(x,y,15,col,tmp);
  61.         x += 8;
  62.         att++;
  63.         i++;
  64.     }
  65.     }
  66. }
  67. void    putmode(int md,int sf,char *str)
  68. {
  69.     static char *sts_str=NULL;
  70.  
  71.     if ( str != NULL )
  72.     sts_str = str;
  73.  
  74.     if ( sts_str != NULL && kb_act != 0 )
  75.     gputs(560,460,XPRG_COL,PRG_COL,sts_str);
  76. }
  77. void    putsys(int len,char *str,char *att)
  78. {
  79.     static BLOCK *save=NULL;
  80.  
  81.     if ( save != NULL ) {
  82.     DSP_pop_vram(save);
  83.     save = NULL;
  84.     }
  85.  
  86.     if ( len > 0 ) {
  87.         save = DSP_push_vram(8,460,len*8+8,479);
  88.     put_put(8,460,len,256,str,att);
  89.     }
  90. }
  91. void    putcnv(int pos,int len,char *str,char *att)
  92. {
  93.     static BLOCK *save1=NULL;
  94.     static BLOCK *save2=NULL;
  95.     int     n;
  96.  
  97.     if ( save1 != NULL ) {
  98.     DSP_pop_vram(save1);
  99.     save1 = NULL;
  100.     }
  101.     if ( save2 != NULL ) {
  102.     DSP_pop_vram(save2);
  103.     save2 = NULL;
  104.     }
  105.  
  106.     if ( len > 0 ) {
  107.     if ( (n = cur_x+len*8) > 640 ) {
  108.         n -= (624);
  109.         save1 = DSP_push_vram(cur_x,cur_y,639,cur_y+15);
  110.         save2 = DSP_push_vram(0,cur_y+16,n,cur_y+31);
  111.     } else
  112.         save1 = DSP_push_vram(cur_x,cur_y,n,cur_y+15);
  113.     put_put(cur_x,cur_y,len,pos,str,att);
  114.     }
  115. }
  116. int    PRG_clic(int no)
  117. {
  118.     int     i,n;
  119.     int     fg;
  120.     char    tmp[256];
  121.  
  122.     if ( prg_tbl[no] == NULL )
  123.     return (no + PRG_NO);
  124.  
  125.     if ( prg_tbl[no]->dir != NULL ) {
  126.     DSP_mos(2);
  127.     if ( prg_tbl[no]->manual == NULL ) {
  128.         if ( (prg_tbl[no]->manual = 
  129.             file_serch(prg_tbl[no]->dir,"*.RRR")) == NULL ) {
  130.             if ( (prg_tbl[no]->manual = 
  131.                 file_serch(prg_tbl[no]->dir,"*.MAN")) == NULL )
  132.             prg_tbl[no]->manual = 
  133.                     file_serch(prg_tbl[no]->dir,"*.DOC");
  134.         }
  135.     }
  136.     if ( prg_tbl[no]->readme == NULL ) {
  137.         if ( (prg_tbl[no]->readme = 
  138.             file_serch(prg_tbl[no]->dir,"*.GGG")) == NULL )
  139.         prg_tbl[no]->readme = 
  140.                 file_serch(prg_tbl[no]->dir,"*.DOC");
  141.     }
  142.     if ( prg_tbl[no]->copycnt == 0 ) {
  143.         if ( (prg_tbl[no]->copy[0] = 
  144.             file_serch(prg_tbl[no]->dir,"*.QQQ")) == NULL ) {
  145.         strcpy(tmp,prg_tbl[no]->dir);
  146.         joint_path(tmp,"*.*");
  147.         prg_tbl[no]->copy[0] = strdup(tmp);
  148.         }
  149.         prg_tbl[no]->copycnt++;
  150.     }
  151.     DSP_mos(0);
  152.     }
  153.  
  154.     MSG_disp("%-29.29s",prg_tbl[no]->name);
  155.     MENU_mask(RETN_NO,ON);
  156.     MENU_mask(LIST_NO,OFF);
  157.     MENU_mask(PRNT_NO,OFF);
  158.     MENU_mask(INST_NO,prg_tbl[no]->copycnt > 0 ? ON:OFF);
  159.     MENU_mask(EXIT_NO,OFF);
  160.  
  161.     if ( prg_tbl[no]->readme != NULL ) {
  162.     MENU_mask(LIST_NO,prg_tbl[no]->manual != NULL ? ON:OFF);
  163.     FILE_open(prg_tbl[no]->readme);
  164.     fg = 0;
  165.     } else if ( prg_tbl[no]->manual != NULL ) {
  166.     MENU_mask(TEXT_NO,prg_tbl[no]->readme != NULL ? ON:OFF);
  167.     FILE_open(prg_tbl[no]->manual);
  168.     fg = 1;
  169.     } else {
  170.     FILE_open(NULL);
  171.     fg = (-1);
  172.     }
  173.  
  174.     n = NON_NO;
  175.     for ( ; ; ) {
  176.     while ( (i = MENU_no(0)) == n )
  177.         FILE_irq();
  178.     n = i;
  179.  
  180.     if ( i == CLER_NO )
  181.         break;
  182.     else if ( i == LIST_NO ) {
  183.         if ( fg == 0 && prg_tbl[no]->manual != NULL ) {
  184.         MENU_mask(TEXT_NO,prg_tbl[no]->readme != NULL ? ON:OFF);
  185.         FILE_open(prg_tbl[no]->manual);
  186.         fg = 1;
  187.         } else if ( fg == 1 && prg_tbl[no]->readme != NULL ) {
  188.         MENU_mask(LIST_NO,prg_tbl[no]->manual != NULL ? ON:OFF);
  189.         FILE_open(prg_tbl[no]->readme);
  190.         fg = 0;
  191.         }
  192.     } else if ( i == PRNT_NO )
  193.         FILE_lpt();
  194.     else if ( i == INST_NO )
  195.         COPY_all(prg_tbl[no]->copycnt,prg_tbl[no]->copy);
  196.     else if ( i == BACK_NO )
  197.         FILE_back();
  198.     else if ( i == NEXT_NO )
  199.         FILE_next();
  200.  
  201.     }
  202.  
  203. #ifdef    DEBUG
  204.     MENU_mask(CLER_NO,OFF);
  205.     MENU_mask(LIST_NO,ON);
  206.     MENU_mask(PRNT_NO,ON);
  207.     MENU_mask(INST_NO,ON);
  208.     MENU_mask(EXIT_NO,ON);
  209. #else
  210.     MENU_mask(CLER_NO,OFF);
  211.     MENU_mask(LIST_NO,OFF);
  212.     MENU_mask(PRNT_NO,OFF);
  213.     MENU_mask(INST_NO,OFF);
  214.     MENU_mask(EXIT_NO,ON);
  215. #endif
  216.     MSG_disp("%-29.29s","");
  217.     FILE_close();
  218.     PRG_status();
  219.  
  220.     return i;
  221. }
  222. int    LIST_proc(void)
  223. {
  224.     int     i,n;
  225.     int     fg=0;
  226.     char    *p,*s;
  227.  
  228. LOOP:
  229.     if ( (p = FILE_select()) == NULL )
  230.     return LIST_NO;
  231.  
  232.     if ( JOKE_run(p) )
  233.     goto LOOP;
  234.  
  235.     MENU_mask(RETN_NO,ON);
  236.     MENU_mask(LIST_NO,OFF);
  237.     MENU_mask(PRNT_NO,ON);
  238.     MENU_mask(INST_NO,OFF);
  239.     MENU_mask(EXIT_NO,OFF);
  240.     FILE_open(p);
  241.  
  242.     n = NON_NO;
  243.     for ( ; ; ) {
  244.     while ( (i = MENU_no(0)) == n )
  245.         FILE_irq();
  246.     n = i;
  247.  
  248.     if ( i == CLER_NO )
  249.         break;
  250.     else if ( i == PRNT_NO )
  251.         FILE_lpt();
  252.     else if ( i == BACK_NO )
  253.         FILE_back();
  254.     else if ( i == NEXT_NO )
  255.         FILE_next();
  256.  
  257.     }
  258.  
  259. #ifdef    DEBUG
  260.     MENU_mask(CLER_NO,OFF);
  261.     MENU_mask(LIST_NO,ON);
  262.     MENU_mask(PRNT_NO,ON);
  263.     MENU_mask(INST_NO,ON);
  264.     MENU_mask(EXIT_NO,ON);
  265. #else
  266.     MENU_mask(CLER_NO,OFF);
  267.     MENU_mask(LIST_NO,OFF);
  268.     MENU_mask(PRNT_NO,OFF);
  269.     MENU_mask(INST_NO,OFF);
  270.     MENU_mask(EXIT_NO,ON);
  271. #endif
  272.     FILE_close();
  273.     PRG_status();
  274.  
  275.     goto LOOP;
  276. }
  277. void    main(int argc,char *argv[])
  278. {
  279.     int     i,n,cdrv;
  280.     char    *p;
  281.     char    *exp;
  282.     char    tmp[4];
  283.  
  284.     cdrv = getdrv();
  285.     tmp[0] = cdrv + 'A'; tmp[1] = ':'; tmp[2] = '\0';
  286.     crent_drive = tmp;
  287.     exp = argv[0];
  288.     index_file[0] = '\0';
  289.  
  290.     if ( argc > 1 ) {
  291.     while ( --argc > 0 ) {
  292.         p = *(++argv);
  293.         if ( *p == '-' || *p == '/' ) {
  294.         switch(toupper(*(p+1))) {
  295.         case 'D':
  296.             p += (*(p+2) == '=' ? 3:2);
  297.             crent_drive = p;
  298.             break;
  299.         }
  300.         } else
  301.         strcpy(index_file,p);
  302.     }
  303.  
  304.     }
  305.  
  306.     if ( index_file[0] == '\0' ) {
  307.     p = exp;
  308.     if ( p[0] != '\0' && p[1] != ':' ) {
  309.         index_file[0] = 'A' + cdrv;
  310.         index_file[1] = ':';
  311.     } else {
  312.         index_file[0] = *(p++);
  313.         index_file[1] = *(p++);
  314.     }
  315.     index_file[2] = '\0';
  316.  
  317.     if ( crent_drive == tmp )
  318.         crent_drive = strdup(index_file);
  319.  
  320.     if ( *p != '\\' ) {
  321.         getdir(index_file+2);
  322.         if ( index_file[3] != '\0' )
  323.         strcat(index_file,"\\");
  324.     }
  325.     strcat(index_file,p);
  326.     if ( (p = strrchr(index_file,'\\')) == NULL )
  327.         for ( p = index_file ; *p != '\0' ; p++ );
  328.     strcpy(p,"\\HELPER.IDX");
  329.     }
  330.  
  331.     DSP_init();
  332.     DSP_mos(2);
  333.  
  334.     ICON_init();
  335.     SCRN_init();
  336.     DB_init(index_file);
  337.     KEY_cler();
  338.     KAN_open(putcnv,putsys,putmode);
  339.  
  340.  
  341. #ifdef    DEBUG
  342.     MENU_mask(CLER_NO,OFF);
  343.     MENU_mask(LIST_NO,ON);
  344.     MENU_mask(PRNT_NO,ON);
  345.     MENU_mask(INST_NO,ON);
  346.     MENU_mask(EXIT_NO,ON);
  347. #else
  348.     MENU_mask(CLER_NO,OFF);
  349.     MENU_mask(LIST_NO,OFF);
  350.     MENU_mask(PRNT_NO,OFF);
  351.     MENU_mask(INST_NO,OFF);
  352.     MENU_mask(EXIT_NO,ON);
  353. #endif
  354.  
  355.     DSP_mos(0);
  356.  
  357.     n = NON_NO;
  358.     for ( ; ; ) {
  359.     while ( (i = MENU_no(1)) == n );
  360.     n = i;
  361.  
  362.     if ( i == EXIT_NO ) {
  363.         if ( yesno("HELPERを終了しますか?") != (-1) )
  364.             break;
  365.     } else if ( i == CLER_NO )
  366.         KEY_cler();
  367. #ifdef    DEBUG
  368.     else if ( i == LIST_NO )
  369.         i = LIST_proc();
  370.     else if ( i == PRNT_NO )
  371.         PLT_control();
  372.     else if ( i == INST_NO )
  373.         KEY_input();
  374. #endif
  375.     else if ( i == BACK_NO )
  376.         PRG_back();
  377.     else if ( i == NEXT_NO )
  378.         PRG_next();
  379.     else if ( i >= PRG_NO )
  380.         i = PRG_clic(i - PRG_NO);
  381.     else if ( i >= KEY_NO )
  382.         KEY_clic(i - KEY_NO);
  383.  
  384.     }
  385.  
  386.     KAN_close();
  387.     DSP_end();
  388.     chdrv(cdrv);
  389. }
  390. void    INKEY_start(void)
  391. {
  392.     kb_act = 1;
  393.     KYB_clrbuf();
  394.     putmode(0,0,NULL);
  395. }
  396. void    INKEY_end(void)
  397. {
  398.     kb_act = 0;
  399.     gputs(560,460,XPRG_COL,PRG_COL,"         ");
  400. }
  401. int    kbhit(void)
  402. {
  403.     if ( kb_flg != 0 )
  404.     return 1;
  405.  
  406.     ch_bak = KAN_read(1,&ec_bak);
  407.  
  408.     if ( (ec_bak & 0xFF00) == 0xFF00 )
  409.     return 0;
  410.  
  411.     kb_flg = 1;
  412.     return 1;
  413. }
  414. int    getch(void)
  415. {
  416.     if ( kbhit() == 0 )
  417.     return EOF;
  418.  
  419.     kb_flg = 0;
  420.     if ( ch_bak  != 0xFFFF ) {
  421.     if ( (ch_bak & 0x8000) != 0 || (ec_bak & 0xFF00) > 0x5100 )
  422.         ch_bak = 0xFFFF;
  423.     switch(ec_bak&0xFF00) {
  424.     case 0x7300: ch_bak = 0x000D; break;
  425.     case 0x7200: ch_bak = 0x001B; break;
  426.     }
  427.     }
  428.     return ((ch_bak & 0xFF00) == 0xFF00 ? EOF:ch_bak);
  429. }
  430. /***********************
  431. int    getch(void)
  432. {
  433.     int     ch;
  434.     unsigned ec;
  435.  
  436.     ch = KYB_read(1,&ec);
  437.     return ((ch & 0xFF00) == 0xFF00 ? EOF:ch);
  438. }
  439. *************************/
  440.